﻿<?xml version="1.0" encoding="utf-8" ?>
<sqlMap namespace="Account"
xmlns="http://ibatis.apache.org/mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >

  <resultMaps>
    
    <resultMap id="resultMap-Document" class="Document">
      <result property="Id"			column="Document_ID"/>
      <result property="Title"		column="Document_Title"/>
    </resultMap>
    
  </resultMaps>
  
  <statements>

    <select id="SelectAccount" parameterClass="int" resultMap="account-result">
      select *
      from Accounts
      where Account_ID = #value#
    </select>

    <select id="SelectAccountViaConstructor" parameterClass="int" resultMap="account-result-constructor">
      select *
      from Accounts
      where Account_ID = #value#
    </select>

    <select id="SelectAccountWithDocument" parameterClass="int" resultMap="account-result-with-document">
      select *
      from Accounts
      where Account_ID = #value#
    </select>

    <insert id="InsertAccount" parameterClass="Account" >
      insert into Accounts
      (Account_ID, Account_FirstName, Account_LastName, Account_Email)
      values
      (
      @{Id}, @{FirstName}, @{LastName}, @{EmailAddress,dbType=VarChar,nullValue=no_email@provided.com}
      )
    </insert>

    <update id="UpdateAccount" parameterClass="Account">
      update Accounts set
      Account_FirstName = @{FirstName},
      Account_LastName = @{LastName},
      Account_Email = @{EmailAddress,type=string,dbType=Varchar,nullValue=no_email@provided.com}
      where
      Account_ID = @{Id}
    </update>

    <select id="SelectDocument" resultMap="resultMap-Document">
      select
      *
      from Documents
      Where Account_ID = #Id#
    </select>
    
  </statements>
</sqlMap >  